Clover coverage report - Flock Flock - 0.7-dev
Coverage timestamp: Thu Jan 30 2003 01:35:37 EST
file stats: LOC: 111   Methods: 11
NCLOC: 76   Classes: 1
This license of Clover is provided to support the development of Flock only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
SimpleSubscriptionManager.java 0% 0% 0% 0%
 1   
 package net.sf.flock.impl;
 2   
 
 3   
 import java.net.URL;
 4   
 import java.util.ArrayList;
 5   
 import java.util.Collection;
 6   
 import java.util.Collections;
 7   
 import java.util.HashMap;
 8   
 import java.util.Iterator;
 9   
 import java.util.List;
 10   
 import java.util.Map;
 11   
 
 12   
 import net.sf.flock.FeedFactoryI;
 13   
 import net.sf.flock.FeedI;
 14   
 import net.sf.flock.FilterI;
 15   
 import net.sf.flock.FlockResourceException;
 16   
 import net.sf.flock.SubscriptionI;
 17   
 import net.sf.flock.SubscriptionInfoI;
 18   
 import net.sf.flock.support.AbstractSubscriptionManager;
 19   
 
 20   
 import org.apache.log4j.LogManager;
 21   
 import org.apache.log4j.Logger;
 22   
 
 23   
 /**
 24   
  * @version $Revision: 1.4 $
 25   
  * @author $Author: phraktle $
 26   
  */
 27   
 public class SimpleSubscriptionManager extends AbstractSubscriptionManager implements FeedFactoryI {
 28   
 
 29   
     private final static Logger LOGGER = LogManager.getLogger(SimpleSubscriptionManager.class);
 30   
 
 31   
     /** Subscriptions hashed by location */
 32   
     private final Map subscriptions = new HashMap();
 33   
 
 34  0
     public FeedI createFeed(SubscriptionInfoI subscriptionInfoI) {
 35  0
         return new Feed(subscriptionInfoI);
 36   
     }
 37   
     
 38  0
     protected synchronized void addSubscription(SubscriptionI subscription) throws FlockResourceException {
 39  0
         if ( this.subscriptions.containsKey(subscription.getLocation()) ) {
 40  0
             throw new FlockResourceException("Feed "+subscription.getLocation()+" already exists in store");
 41   
         }
 42  0
         this.subscriptions.put(subscription.getLocation(), subscription);
 43   
     }
 44   
 
 45  0
     public SubscriptionI getSubscription(URL location) throws FlockResourceException {
 46  0
         return (SubscriptionI)this.subscriptions.get(location);    
 47   
     }
 48   
 
 49  0
     protected Collection getSubscriptions() {
 50  0
         return Collections.unmodifiableCollection(this.subscriptions.values());
 51   
     }
 52   
 
 53  0
     public Collection getSubscriptionInfos() throws FlockResourceException {
 54  0
         return this.getSubscriptions();
 55   
     }
 56   
 
 57  0
     public void unsubscribe(URL location) throws FlockResourceException {
 58  0
         if (this.subscriptions.remove(location)==null) {
 59  0
             throw new FlockResourceException("No subscription for location "+location);
 60   
         }
 61   
     }
 62   
     
 63  0
     public void refresh(URL location) throws FlockResourceException {
 64  0
         Subscription subscription = (Subscription)this.subscriptions.get(location);
 65  0
         if ( subscription==null ) {
 66  0
             throw new FlockResourceException("No subscription for location "+location);
 67   
         }
 68   
         
 69  0
         this.refresh(subscription);
 70   
     }
 71   
 
 72  0
     public Collection findItems(FilterI[] filters) throws FlockResourceException {
 73  0
         List items = new ArrayList();
 74  0
         for (Iterator i=this.getSubscriptions().iterator(); i.hasNext();) {
 75  0
             SubscriptionI subscription = (SubscriptionI) i.next();
 76  0
             items.addAll( subscription.getFeed().getItems() );
 77   
         }
 78   
         
 79  0
         for (int i=0; i<filters.length; i++) {
 80  0
             items = filters[i].filter(items);
 81   
         }
 82   
 
 83  0
         return items;
 84   
     }
 85   
     /**
 86   
      * @see net.sf.flock.support.AbstractSubscriptionManager#createSubscription(net.sf.flock.SubscriptionInfoI)
 87   
      */
 88  0
     protected SubscriptionI createSubscription(SubscriptionInfoI subscriptionInfo) throws FlockResourceException {
 89  0
         return new Subscription(subscriptionInfo.getLocation(), subscriptionInfo.getMetaData());
 90   
     }
 91   
 
 92   
 
 93   
     /**
 94   
      * @see net.sf.flock.SubscriptionManagerI#subscribe(net.sf.flock.SubscriptionInfoI, boolean)
 95   
      */
 96  0
     public SubscriptionI[] subscribe(SubscriptionInfoI subscriptionInfo, boolean load) throws FlockResourceException {
 97  0
         SubscriptionI[] subs = super.subscribe(subscriptionInfo, load);
 98  0
         for (int i=0; i<subs.length; i++){
 99  0
             this.addSubscription(subs[i]);
 100   
         }
 101  0
         return subs;
 102   
     }
 103   
     /**
 104   
      * @see net.sf.flock.support.AbstractSubscriptionManager#getFeedFactory()
 105   
      */
 106  0
     protected FeedFactoryI getFeedFactory() {
 107  0
         return this;
 108   
     }
 109   
 
 110   
 }
 111